package inventory.controller;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import inventory.common.CommonConstants;
import inventory.common.ResultData;
import inventory.entity.User;
import inventory.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * @author Jwx
 * @create 2019-10-28 21:28
 */
@RestController
@RequestMapping(CommonConstants.API_VERSION+"/user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 前端传入要修改用户
     * 根据id修改用户信息
     * @return
     */
    @RequestMapping(value = "/modify",method = RequestMethod.POST,params = {"userId"})
    public ResultData modify(User user){
        userService.modifyById(user);
        return new ResultData().OK();
    }


    /**
     * 前端传入要增加的用户对象
     * 新增用户
     * @return
     */
    @RequestMapping(value = "/addUser",method = RequestMethod.POST,params = {"User"})
    public ResultData addUser(User user){
        user.setUserId(String.valueOf(UUID.randomUUID()));
        userService.modifyById(user);
        return new ResultData().OK();
    }

    /**
     * 前端传入userId，返回改userId对应的User对象
     * 根据id获取用户
     * @return
     */
    @RequestMapping(value = "queryUserById",method = RequestMethod.POST,params = {"userId"})
    public ResultData queryUserById(String userId){

        User user = userService.queryUserById(userId);
        return new ResultData().setObjs(user);
    }

    /**
     * 前端传入userId和用户类型返回改userId对应的User对象
     * 根据id和用户类型删除用户
     * @return
     */
    @RequestMapping(value = "/deleteUserByIdAndType",method = RequestMethod.POST)
    public ResultData deleteUserByIdAndType(String userId){
        Integer id=userService.deleteUserById(userId);
        return new ResultData().setResultStatus(id);
    }

}

